package it.blog.controller;

import it.blog.stub.BlogPortal;
import it.blog.stub.BlogPortalService;

import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;

public class Logout extends HttpServlet {

	private static final long serialVersionUID = -3070835087343514327L;
	
	
	// DOBBIAMO VEDERE COME GESTIRE IL LOGOUT SUL WEB SERVER
	
	@Override
	protected void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException {
		//Invalido la sessione		
		BlogPortal bp = new BlogPortalService().getPort(BlogPortal.class);
		HttpSession session = request.getSession();
		String sessionId= session.getId();
		bp.removeUserSession(sessionId);
		session.setAttribute("user",null);
		session.invalidate();
		
		
		response.sendRedirect(response.encodeRedirectURL(request.getContextPath()+"/PortalServlet"));
	}

}
